<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="resources/jquery.js"></script>
  <link rel="stylesheet" href="css/common.css">
  <link rel="stylesheet" href="css/catalog.css">

  <meta charset="UTF-8">
  <script>
    function hideAllSubs() {
      $(".listSubElems").hide('fast');
      $(".listItemImg img").attr('src', "img/plus.png")
    }

    function showSub(listId) {
      if ($("#sub" + listId).css("display") == 'none') {
        hideAllSubs();
        $("#sub" + listId).slideDown('fast');
        $("#elemImg" + listId).attr('src', "img/minus.png");
      } else {
        hideAllSubs();
      }
    }

  </script>
</head>
<?php
/**
 * Created by PhpStorm.
 * User: Aliaksei Lazerka
 * Date: 10/20/14
 * Time: 10:03 PM
 */

include_once("functions/db_manipulate.php");
include_once("elems/homeButton.php");

$listRoots = getListRoots($_GET['sid']);
$hasRootElems = false;

?>
<body>
<div class="listHeader">
  <?= getSectionTitle($_GET['sid']) ?>

  <div class="listDiv">
    <?php

    while ($listRoot = mysql_fetch_assoc($listRoots)) {
      if (!$hasRootElems) {
        $hasRootElems = true;
      }
      ?>
      <div class="listItemRoot" onclick="showSub('<?= $listRoot['ID'] ?>')">

        <div class="listItemImg">
          <img src="img/plus.png" id="elemImg1"/>
        </div>
        <div class="listItemRootContent">
          <?= $listRoot['TITLE'] ?>
        </div>
        <div class="listSubElems" id="sub<?= $listRoot['ID'] ?>">
          <?php
          $listSubs = getListSubs($listRoot['ID']);

          if ($listSub = mysql_fetch_assoc($listSubs)) {
            ?>
            <div class="listSubElem">
              <a target="_blank" href="?table&lid=<?= $listSub['ID']?>"><?= $listSub['TITLE'] ?></a>
            </div>
          <?php
          } else {
            ?>
            <div class="listSubElem">
              --------------------------
            </div>
          <?php
          }

          while ($listSub = mysql_fetch_assoc($listSubs)) {
            ?>
            <div class="listSubElem">
              <a target="_blank" href="?table&lid=<?= $listSub['ID']?>"><?= $listSub['TITLE'] ?></a>
            </div>
          <?php
          }
          ?>
        </div>
      </div>

    <?php
    }

    if (!$hasRootElems) {
      echo "В данном разделе продукция отсутствует";
    }
    ?>
  </div>
</div>
</body>